package com.potato.common.utils;

import android.content.Context;
import android.net.Uri;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.bumptech.glide.request.RequestOptions;

/**
 * Created by dengxudong on 2018/5/18.
 */

public class GlideUtils {

    public static void shoImage(Context context, ImageView imageView , Uri val){
        if(val==null){return;}
        try {
            Glide.with(context)
                    .load(val)
                    .apply(new RequestOptions().centerCrop())
                    .transform(new RoundedCorners(15))
                    .placeholder(imageView.getDrawable())
                    .into(imageView);
        } catch (Exception e) {
            e.printStackTrace();
        } catch (NoSuchMethodError noSuchMethodError){
            noSuchMethodError.printStackTrace();
        }
    }

    public static void displayImage(Context context, Object path, ImageView imageView) {
        Glide.with(context).load(path) .transform(new RoundedCorners(15))
                .placeholder(imageView.getDrawable()).into(imageView);
    }

    public static void shoImage(Context context, ImageView imageView , String val){
        if(val==null){return;}
        try {
            Glide.with(context)
                    .load(val)
                    .apply(new RequestOptions().centerCrop())
                    .transform(new RoundedCorners(15))
                    .placeholder(imageView.getDrawable())
                    .into(imageView);
        } catch (Exception e) {
            e.printStackTrace();
        } catch (NoSuchMethodError noSuchMethodError){
            noSuchMethodError.printStackTrace();
        }
    }
}
